package com.socene.kotlin.service

import com.socene.kotlin.bean.BaseService
import com.socene.kotlin.dao.UserRepository
import com.socene.kotlin.entity.User
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Service


/* *
 *Created by: Sorata 2017/11/9 0009 上午 10:48
 *
 */
@Service
class UserService : BaseService<User, Int>() {

    @Autowired lateinit var userRepository: UserRepository

    override val repository: JpaRepository<User, Int>
        get() = userRepository

    fun findByUsername(name: String) = userRepository.findByUsername(name)

    fun findUserPage(password: String,page:Int,limit:Int):Page<User>{
        val pageable = PageRequest(page,limit,Sort.Direction.DESC,"createTime")
        return userRepository.findByPassword(password, pageable)
    }

    fun findUser(name: String,password:String) = userRepository.selectUser(name,password)
}
